package cn.com.infohold.smartcity.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;

import java.util.ArrayList;
import java.util.List;

import cn.com.infohold.smartcity.R;
import cn.com.infohold.smartcity.fragment.approve_manage.Frgm_Not_Approve;
import cn.com.infohold.smartcity.fragment.approve_manage.Frgm_Approve;
import cn.com.infohold.smartcity.fragment.dipute_manage.Frgm_Dispute;
import cn.com.infohold.smartcity.fragment.dipute_manage.Frgm_Not_Dispute;
import cn.com.infohold.smartcity.parent.ParentActivity;
import common.annotation.ViewInject;


public class MainActivity extends ParentActivity {

    @ViewInject(R.id.ib_back)
    ImageButton ib_back;
    @ViewInject(R.id.mTablayout)
    TabLayout mTablayout;
    @ViewInject(R.id.vp_content)
    ViewPager mViewPager;

    private List<String> mTabs;
    private List<Fragment> mFragments;
    private Frgm_Dispute frgm_fabaofang;
    private Frgm_Approve frgm_chengbaofang;
    private Frgm_Not_Approve frgm_business;
    private Frgm_Not_Dispute frgm_warrant;
    //private ContentPagerAdapter contentAdapter;

    @Override
    protected Object inflateView() {
        return R.layout.activity_main;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void initView(View anchor) {

        ib_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                overridePendingTransitionFade();
            }
        });
        initTab();
        initViewPager();

    }

    private void initTab(){
        mTablayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        mTablayout.setTabTextColors(ContextCompat.getColor(this, R.color.black),ContextCompat.getColor(this,R.color.colorPrimary));
        mTablayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.colorPrimary));
        ViewCompat.setElevation(mTablayout,6);
        mTablayout.setupWithViewPager(mViewPager);

    }
    private void initViewPager(){
        mTabs = new ArrayList<>();
        mTabs.add("发包方管理");
        mTabs.add("承包方管理");
        mTabs.add("经营方管理");
        mTabs.add("权证管理");

        frgm_fabaofang = new Frgm_Dispute();
        frgm_chengbaofang = new Frgm_Approve();
        frgm_business = new Frgm_Not_Approve();
        frgm_warrant = new Frgm_Not_Dispute();

        mFragments = new ArrayList<>();
        mFragments.add(frgm_fabaofang);
        mFragments.add(frgm_chengbaofang);
        mFragments.add(frgm_business);
        mFragments.add(frgm_warrant);

        ViewPagerAdapter mAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mAdapter);

    }

    class ViewPagerAdapter extends FragmentPagerAdapter{

        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mTabs.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTabs.get(position);
        }
    }

}
